const Ajv = require('ajv');

const schema = {
    type: 'object',
    properties: {
        name: {
            type: 'string',
            format: 'test',
            // minLength: 5,
        },
        age: {
            type: 'number',
        },
        pets: {
            type: 'array',
            items: {
                type: 'string',
            },
        },
        isWorker: {
            type: 'boolean',
        }
    }
};

const ajv = new Ajv();
ajv.addFormat('test',(data)=>{
    console.log(data, '----------');
    return data === 'haha';
})
const validate = ajv.compile(schema);
const valid = validate({
    name: 'haha',
    age: 30,
    pets: ['cat', 'dog'],
    isWorker: true,
});
if (!valid) {
    console.log(validate.errors);
}
